#include <cstdio>

int f[ 2001 ][ 2001 ];

int main( )
{
    int t, n, i, j, p;
    f[ 1 ][ 1 ] = 1;
    for ( i = 2; i <= 2000; i++ )
    {
        f[ i ][ 1 ] = 1;
        for ( j = 2; j < i; j++ )
            f[ i ][ j ] = ( f[ i - 1 ][ j ] * j + f[ i - 1 ][ j - 1 ] ) % 1000;
        f[ i ][ i ] = 1;
    }
    scanf("%d", &t);
    while ( t-- )
    {
        scanf("%d", &n);
        p = 0;
        for ( i = 1; i <= n; i++ )
            p = ( p + f[ n ][ i ] ) % 1000;
        printf("%d\n", p);
    }
    return 0;
}
